package 
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.NetStatusEvent;
	import flash.media.Camera;
	import flash.media.Video;
	import flash.net.NetConnection;
	import flash.net.NetStream;
	
	/**
	 * ...
	 * @author Devin Lee
	 */
	public class Main extends Sprite 
	{
		private var net:NetConnection;
		private var _videoURL:String = "../lib/PK土豆/117599197.h264_1.f4v";
		
		public function Main():void 
		{
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			// entry point
			net = new NetConnection();
			trace("[Main]>>>init:",net);
			net.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
			net.connect(null);
		}
		
		private function onNetStatus(e:NetStatusEvent):void 
		{
			trace("[Main]>>>onNetStatus:",e.info.code);
			switch(e.info.code) {
				case "NetConnection.Connect.Success":
					connectStream();
					break
				case "NetStream.Play.StreamNotFound":
					trace("[Main]>>>onNetStatus:NetStream.Play.StreamNotFound ", _videoURL);
					break;
			}
		}
		
		private function connectStream():void 
		{
			var ns:NetStream = new NetStream(net);
			ns.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
			ns.client = new CustomClient();
			var video:Video = new Video();
			addChild(video);
			video.attachNetStream(ns);
			ns.play(_videoURL);
		}
		
	}
	
}
class CustomClient {
    public function onMetaData(info:Object):void {
        trace("metadata: duration=" + info.duration + " width=" + info.width + " height=" + info.height + " framerate=" + info.framerate);
    }
    public function onCuePoint(info:Object):void {
        trace("cuepoint: time=" + info.time + " name=" + info.name + " type=" + info.type);
    }
}